package com.cqust.icc.sqlite;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.cqust.icc.sqlite.db.baseDbActivity;

public class LoginActivity extends baseDbActivity {

    private TextView input1;
    private TextView input2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        input1 = findViewById(R.id.input_1);
        input2 = findViewById(R.id.input_2);

    }

    //登录
    public void loginClick(View view) {

        String name = input1.getText().toString();
        String pwd = input2.getText().toString();

        if (TextUtils.isEmpty(name)) {
            Toast.makeText(LoginActivity.this, "请输入账号~", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(pwd)) {
            Toast.makeText(LoginActivity.this, "请输入密码~", Toast.LENGTH_SHORT).show();
            return;
        }

        String login = dbService.login(name);
        if (pwd.equals(login)) {
            Toast.makeText(LoginActivity.this, "登录成功~", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(LoginActivity.this, MainActivity.class).putExtra("username", name));
            finish();
        } else {
            Toast.makeText(LoginActivity.this, "密码错误~", Toast.LENGTH_SHORT).show();
        }
    }

    //注册
    public void regClick(View view) {
        startActivity(new Intent(LoginActivity.this, RegActivity.class));
    }


}